package com.liangwj.springbootrabbitmq.rabbit;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * <b>Description:</b> topic 是RabbitMQ中最灵活的一种方式，可以根据routing_key自由的绑定不同的队列 <br/>
 * @author Lingwenjun
 * @date 2019/1/14-16:04
 * @version 1.0
 */
@Configuration
public class TopicRabbitMQConfig {

    private final static String message = "topic.message";
    private final static String messages = "topic.messages";

    @Bean
    public Queue queueMessage() {
        return new Queue(TopicRabbitMQConfig.message, false, false, true);
    }

    @Bean
    public Queue queueMessages() {
        return new Queue(TopicRabbitMQConfig.messages, false, false, true);
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange("exchange", false,true);
    }

    @Bean
    Binding bindingExchangeMessage(Queue queueMessage, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message");

    }

    @Bean
    Binding bindingExchangeMessages(Queue queueMessages, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessages).to(exchange).with("topic.#");
    }
}
